package com.example.photography.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.photography.R;
import com.example.photography.bean.UrlBean;
import com.example.photography.util.Util;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public abstract class PhotoAdapter extends MyBaseAdapter {

    public PhotoAdapter(List list, Context context) {
        super(list, context);
    }

    @Override
    public View myGetView(int position, View convertView) {
        //1 获取或创建viewHolder
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_product, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //2 获取当前item数据
        UrlBean urlBean = (UrlBean) list.get(position);
        Glide.with(mContext)
                .load(urlBean.getUrl())
                .thumbnail(Glide.with(mContext).load(R.drawable.loading))
                .into(holder.ivProduct);
        ViewHolder finalHolder = holder;
        holder.ivProduct.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onclick(urlBean.getUrl());
            }
        });
        return convertView;
    }

    static
    class ViewHolder {
        @BindView(R.id.iv_product)
        ImageView ivProduct;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
    public abstract void onclick(String url);
}
